
If (isNil "D_CURRENT_BUILDING_LIST") then {D_CURRENT_BUILDING_LIST = _initial_list};

_house_positions = [
];

// those functions transforms the arrays extracted from the logfile to something useable.

if ((count D_DONE_POSITIONS_LIST > 0) || (count _house_positions > 0)) then {
	diag_log Format["Begin treating %1 positions",D_DONE_POSITIONS_LIST];
	D_BUILDING_INDEXER = [];
	D_BUILDING_TABLE = [];
	_house_positions = [_house_positions,D_DONE_POSITIONS_LIST] call XfArrayPushStack;
	_houses_indexer = [];
	_houses_positions = [];
	_house_subarray = [];
	{
		diag_log Format["Item: %1",_x];
		_house_type = _x select 0;
		_position_type = _x select 1;
		_position_rel = _x select 2;
		_position_dir = _x select 3;
		_pos = _houses_indexer find _house_type;
		 diag_log Format["Pos: %1",_pos];
		if (_pos == -1) then {
			_pos = count _houses_indexer;
			_houses_indexer set [count _houses_indexer, _house_type];
		};
		if (_pos > count _houses_positions) then {
			_houses_positions set [_pos, [[],[],[]]];
			_house_subarray = _houses_positions select _pos;
		} else {
			_house_subarray = _houses_positions select _pos;
			if (isNil "_house_subarray") then {
				_houses_positions set [_pos, [[],[],[]]];
				_house_subarray = _houses_positions select _pos;
			};
		};
		 diag_log Format["Sub array: %1",_house_subarray];
		_position_list = _house_subarray select (_position_type);
		diag_log Format["Pos list: %1",_position_list];
		_position_list set [count _position_list, [_position_rel,_position_dir]];
		_house_subarray set [(_position_type), _position_list];
		_houses_positions set [_pos, _house_subarray];
	}foreach _house_positions;

	diag_log "#BUILDING_POSITION_INDEXER = [#";
	{
		D_BUILDING_INDEXER set [count D_BUILDING_INDEXER, _x];
		diag_log Format["#	,%1#",str(_x)];
	} foreach _houses_indexer;
	diag_log "#];#";


	diag_log "#BUILDING_POSITION_INFOS = [#";
	for [{_i = 0},{_i < count _houses_indexer},{_i = _i + 1}] do
	{
		hintsilent Format["Buildings Left: %1",(count _houses_indexer) - _i];
		diag_log Format["#	//Building: %1#",(_houses_indexer select _i)];
		diag_log Format["#	[#"];
		_positions = _houses_positions select _i;
		diag_log Format["#		// Inside combat positions (windows, doors)#"];
		diag_log Format["#		[#"];
		_first = true;
		_table_inside = [];
		{
			if (_first) then {
				diag_log Format["#			%1#",_x];
				_first = false;
			} else {
				diag_log Format["#			,%1#", _x];
			};
			_table_inside set [count _table_inside, _x];
		} foreach (_positions select 0);
		diag_log Format["#		],#"];

		diag_log Format["#		// Inside hiding positions (for AIs to hide like assassination targets#"];
		diag_log Format["#		[#"];
		_first = true;
		_table_hide = [];
		{
			if (_first) then {
				diag_log Format["#			%1#",_x];
				_first = false;
			} else {
				diag_log Format["#			,%1#", _x];
			};
			_table_hide set [count _table_hide, _x];
		} foreach (_positions select 1);
		diag_log Format["#		],#"];

		diag_log Format["#		// Roof positions for snipers#"];
		diag_log Format["#		[#"];
		_first = true;
		_table_sniper = [];
		{
			if (_first) then {
				diag_log Format["#			%1#",_x];
				_first = false;
			} else {
				diag_log Format["#			,%1#", _x];
			};
			_table_sniper set [count _table_sniper, _x];
		} foreach (_positions select 2);
		diag_log Format["#		]#"];

		diag_log Format["#	],#"];
		D_BUILDING_TABLE set [count D_BUILDING_TABLE, [_table_inside, _table_hide, _table_sniper]];
	};
	diag_log "#];#";
	hint "Done creating building table";
} else {
	hint "No positions to build from";
};

